package la.iok.hzsvn.lewin.movie.shopmovie.controller;

import la.iok.hzsvn.lewin.movie.core.Token;
import la.iok.hzsvn.lewin.movie.shopmovie.model.CarpoolReport;
import la.iok.hzsvn.lewin.movie.shopmovie.model.JoinPlayerResult;
import la.iok.hzsvn.lewin.movie.shopmovie.model.PlayerJoinCarpoolParam;
import la.iok.hzsvn.lewin.movie.shopmovie.service.CarpoolService;
import la.iok.hzsvn.lewin.movie.shopmovie.service.CouponUseRecordService;
import la.iok.hzsvn.lewin.movie.shopmovie.service.PlayerService;
import la.iok.hzsvn.share.response.OperatorResponse;
import la.iok.hzsvn.share.response.OperatorResponses;
import la.iok.hzsvn.share.response.SingleDataResponse;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("players")
public class PlayerController {
    private final CarpoolService carpoolService;
    private final PlayerService playerService;
    private final CouponUseRecordService couponUseRecordService;

    public PlayerController(CarpoolService carpoolService,
                            PlayerService playerService,
                            CouponUseRecordService couponUseRecordService) {
        this.carpoolService = carpoolService;
        this.playerService = playerService;
        this.couponUseRecordService = couponUseRecordService;
    }

    @PostMapping
    public SingleDataResponse<JoinPlayerResult> save(@RequestHeader Token token, @RequestBody PlayerJoinCarpoolParam param){
        return new SingleDataResponse<>(carpoolService.joinPlayer(token,param));
    }

    @DeleteMapping("{id}")
    public OperatorResponse deletePlayer(@RequestHeader Token token, @PathVariable Long id){
        couponUseRecordService.deletePlayer(token, id);
        return OperatorResponses.success();
    }
    @PutMapping("{id}/remark")
    public OperatorResponse updateRemark(@RequestHeader Token token, @PathVariable Long id, @RequestBody String remark) {
        carpoolService.updateRemark(token, id, remark);
        return OperatorResponses.success();
    }

    @PostMapping("cs/report")
    public SingleDataResponse<CarpoolReport> customServicePlayerReport(@RequestHeader Token token, @RequestBody CarpoolReport report) {
        return new SingleDataResponse<>(playerService.customServicePlayerCountReport(token, report));
    }
}
